<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>选项卡</title>
    <script src="./vue copy.js"></script>
    <style>
      * {
        margin: 0;
        padding: 0;
        list-style: none;
      }
      .box{
        width: 600px;
        height: 200px;
        border: 1px solid black;
        position: relative;
      }

      .title {
        height: 74px;
        width: 100%;
        display: flex;
      }

      .title-item {
        flex: 1;
        text-align: center;
        font-size: 30px;
        line-height: 74px;
        border: 1px solid black;
      }

      .text {
        position: absolute;
        height: 126px;
        width: 600px;
        top: 74px;
        left: 0;
        background-color: pink;
      }

      p {
        width: 100%;
        height: 16px;
        font-size: 20px;
        margin-bottom: 16px;
        text-align: start;
        line-height: normal;
      }
      .active {
        background-color: skyblue;
        color: #fff;
      }
    </style>
  </head>
<body>
<div id="app">
  <div class="box">
    <div class="title">
      <div
        class="title-item"
        :class="{active:item.isShow}"
        v-for="(item,index) in title"
        :key="index"
        @click="change(item)"
      >
        {{item.name}}

         <!-- 显示在父级下面是通过定位,定位的对象是[box]这个盒子,给box设置 position: relative; -->
        <div class="text" v-show="item.isShow">
          <p v-for="(textItem,index) in item.products" :key="index">
            {{textItem.name}}----${{textItem.price}}
          </p>
        </div>
      </div>
    </div>
  </div>
</div>

<script>
  var vm = new Vue({
    el: "#app",
    data: {
      title: [
        {
          id: 1,
          name: "数码",
          isShow: true,
          products: [
            {
              id: 1,
              name: "Macbook Pro 2022",
              price: 998,
            },
            {
              id: 2,
              name: "iphone 14 Pro Mini",
              price: 588,
            },
            {
              id: 3,
              name: "ipod",
              price: 8,
            },
          ],
        },
        {
          id: 2,
          name: "服饰",
          isShow: false,
          products: [
            {
              id: 4,
              name: "精神小伙爆款旺仔牛奶全身套",
              price: 99,
            },
            {
              id: 5,
              name: "潮牌豆豆鞋",
              price: 59,
            },
            {
              id: 6,
              name: "牌牌琦电动车",
              price: 1999,
            },
          ],
        },
        {
          id: 3,
          name: "其他",
          isShow: false,
          products: [
            {
              id: 7,
              name: "一罐空气",
              price: 0.5,
            },
            {
              id: 8,
              name: "老头环",
              price: 298,
            },
            {
              id: 9,
              name: "猫抓板",
              price: 10,
            },
          ],
        },
      ],
    },
    methods: {
      change(value) {
        this.title.forEach((item) => {
          item.isShow = false;
        });
        value.isShow = true;
      },
    },
  });
</script>
</body>
</html>
